<?php 

if(Yii::app()->user->hasFlash('model')) {
	Yii::app()->user->flash('model', array('<div class="confirmation">', '</div>'));
	return;
}

$tinymce = Html::jsUrl('tiny_mce/tiny_mce.js');
$script = <<<EOD
$('.bigText').tinymce({
script_url : '$tinymce',
theme : "advanced",
width : "480",
height: "500",

plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

 

// Theme options

theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",

theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,charmap,emotions,iespell,media,advhr",

theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,print",

theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,forecolor,backcolor",

theme_advanced_buttons5 :
"styleselect,formatselect,fontselect,fontsizeselect,ltr,rtl,|,fullscreen",
theme_advanced_toolbar_location : "top",

theme_advanced_toolbar_align : "left",

theme_advanced_statusbar_location : "bottom",

theme_advanced_resizing : true,

font_size_style_values: "xx-small",

});

               $(window).trigger("load");
EOD;


	if($_SERVER['HTTP_X_REQUESTED_WITH'] ? $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest' : false){
		echo "<script type=\"text/javascript\">$.getScript(\"".Html::jsUrl('tiny_mce/jquery.tinymce.js')."\", function(){".$script."});</script>\n";

	}else{

		Yii::app()->clientScript->registerScriptFile(Html::jsUrl('tiny_mce/jquery.tinymce.js')); 
		Yii::app()->clientScript->registerScript('jq1',$script,CClientScript::POS_READY);
	}

?>

<div class="yiiForm" style="width:90%">

<?php echo Html::beginForm(); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo Html::errorSummary($model); ?>

	<div class="simple">
		<?php echo Html::activeLabelEx($model,'title'); ?>
		<?php echo Html::activeTextField($model,'title',array('size'=>80,'maxlength'=>128)); ?>
		<?php echo Html::error($model,'title'); ?>
	</div>

	<div class="simple">
		<?php echo Html::activeLabel($model,'category_id'); ?>
		<?php echo Html::activedropDownList($model, 'category_id', CHtml::listData(Category::model()->findAll(), 'id', 'title'), array('empty' =>'Chose category')); ?>
	</div>

	<div class="simple">
		<?php echo Html::activeLabelEx($model,'content'); ?>
		<?php echo Html::activeTextArea($model,'content',array('rows'=>10, 'cols'=>70, 'class'=>'bigText')); ?>
		<?php echo Html::error($model,'content'); ?>
	
	</div>
	<div class="simple">
		<?php echo Html::activeLabelEx($model,'tags'); ?>
		<?php $this->widget('CAutoComplete', array(
			'model'=>$model,
			'attribute'=>'tags',
			'url'=>array('suggestTags'),
			'multiple'=>true,
			'htmlOptions'=>array('size'=>50),
		)); ?>
		<p class="hint">Please separate different tags with commas.</p>
		<?php echo Html::error($model,'tags'); ?>
	</div>

	<?php if(Yii::app()->user->hasAuth(Group::TEACHER)): ?>
 	<div class="simple">
		<?php echo Html::activeLabelEx($model,'status',array('style'=>'width:80px;')); ?>
		<?php echo Html::activeDropDownList($model,'status',Lookup::items('PostStatus')); ?>
		<?php echo Html::error($model,'status'); ?>
	</div>
	<?php endif; ?>
	<div class="action">
		<?php echo Html::submitButton($model->isNewRecord ? 'Publish' : 'Save',array('class'=>'submit')); ?>
	</div>

<?php echo Html::endForm(); ?>

</div><!-- form -->
<script type="text/javascript">
$('form').bind("submit", function() { return false; });

$('.submit').bind("click", function () {
  jQuery.ajax({
'type':'POST',
'dataType' : 'html',
'url': jQuery(this).parents("form").attr("action"),
'cache':false,
'data':jQuery(this).parents("form").serialize(),
'success':function(html){
jQuery("#content").html(html)}
});
  return false;
});
</script>
